package com.krain.meijusky.entity;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.Map;

/**
 * Class description
 *
 * @author yamin
 * @date 2015/11/2 上午 11:28
 */
public class ResourceEntity implements Parcelable {

    String nextUrl;

    String img;

    String title;

    Map<String, String> attributes;

    String attrs;


    public ResourceEntity() {
    }

    public String getNextUrl() {
        return nextUrl;
    }

    public void setNextUrl(String nextUrl) {
        this.nextUrl = nextUrl;
    }

    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Map<String, String> getAttributes() {
        return attributes;
    }

    public void setAttributes(Map<String, String> attributes) {
        this.attributes = attributes;
    }

    public String getAttrs() {
        return attrs;
    }

    public void setAttrs(String attrs) {
        this.attrs = attrs;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.nextUrl);
        dest.writeString(this.img);
        dest.writeString(this.title);
        dest.writeString(this.attrs);
        if (attributes !=null){
            dest.writeInt(this.attributes.size());
            for (Map.Entry<String, String> entry : this.attributes.entrySet()) {
                dest.writeString(entry.getKey());
                dest.writeString(entry.getValue());
            }
        }


    }

    protected ResourceEntity(Parcel in) {
        this.nextUrl = in.readString();
        this.img = in.readString();
        this.title = in.readString();
        this.attrs = in.readString();
        if (this.attributes !=null){
            for (int i = 0; i < in.readInt(); i++) {
                String key = in.readString();
                String value = in.readString();
                this.attributes.put(key, value);
            }
        }


    }

    public static final Creator<ResourceEntity> CREATOR = new Creator<ResourceEntity>() {
        public ResourceEntity createFromParcel(Parcel source) {
            return new ResourceEntity(source);
        }

        public ResourceEntity[] newArray(int size) {
            return new ResourceEntity[size];
        }
    };
}
